package com.jlu.yygh.controller;

import com.jlu.yygh.common.result.Result;
import com.jlu.yygh.common.utils.AuthContextHolder;
import com.jlu.yygh.model.user.Patient;
import com.jlu.yygh.service.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

//就诊人管理接口
@RestController
@Api(tags = "就诊人管理接口")
@RequestMapping("/api/user/patient")
public class PatientApiController {
  @Autowired
  private PatientService patientService;
  //获取就诊人列表
  @GetMapping("auth/findAll")
  @ApiOperation(value = "获取就诊人列表")
  public Result findAll(HttpServletRequest request) {
    //获取当前登录用户id
    Long userId = AuthContextHolder.getUserId(request);
    List<Patient> list = patientService.findAllUserId(userId);
    return Result.ok(list);
  }
  //添加就诊人
  @PostMapping("auth/save")
  @ApiOperation(value = "添加就诊人")
  public Result savePatient(@RequestBody Patient patient, HttpServletRequest request) {
    //获取当前登录用户id
    Long userId = AuthContextHolder.getUserId(request);
    patient.setUserId(userId);
    patientService.save(patient);
    return Result.ok();
  }
  //根据id获取就诊人信息
  @GetMapping("auth/get/{id}")
  @ApiOperation(value = "根据id获取就诊人信息")
  public Result getPatient(@PathVariable Long id) {
    Patient patient = patientService.getPatientId(id);
    return Result.ok(patient);
  }
  //修改就诊人
  @PutMapping("auth/update")
  @ApiOperation(value = "修改就诊人")
  public Result updatePatient(@RequestBody Patient patient) {
    patientService.updateById(patient);
    return Result.ok();
  }
  //删除就诊人
  @DeleteMapping("auth/remove/{id}")
  @ApiOperation(value = "删除就诊人")
  public Result removePatient(@PathVariable Long id) {
    patientService.removeById(id);
    return Result.ok();
  }

  @ApiOperation(value = "获取就诊人")
  @GetMapping("inner/get/{id}")
  public Patient getPatientOrder(@PathVariable("id") Long id) {
    return patientService.getById(id);
  }
}
